// initial state
const state = {
  user: {
    sexEnum: [{ key: 1, value: '男' }, { key: 2, value: '女' }],
    statusEnum: [{ key: 1, value: '启用' }, { key: 2, value: '禁用' }],
    userLevelEnum: [
      {key: 2018, value: '2018级'},
      {key: 2019, value: '2019级'},
      {key: 2020, value: '2020级'},
      {key: 2021, value: '2021级'},
      {key: 2022, value: '2022级'},
      {key: 2023, value: '2023级'},
      {key: 2024, value: '2024级'},
      {key: 2025, value: '2025级'},
      {key: 2026, value: '2026级'},
      {key: 2027, value: '2027级'},
      {key: 2028, value: '2028级'}
    ],
    statusTag: [{ key: 1, value: 'success' }, { key: 2, value: 'danger' }],
    statusBtn: [{ key: 1, value: '禁用' }, { key: 2, value: '启用' }],
    roleEnum: [{ key: 1, value: '管理员' }, { key: 2, value: '学生' }],
  },
  question: {
    typeEnum: [{ key: 1, value: '单选题' }, { key: 2, value: '多选题' }, { key: 3, value: '判断题' }],
    editUrlEnum: [
      { key: 1, value: '/question/single-choice', name: '单选题' },
      { key: 2, value: '/question/multiple-choice', name: '多选题' },
      { key: 3, value: '/question/true-false', name: '判断题' }
    ]
  },
  courseware: {
    coursewareEnum: [{ key: 1, value: '视频' }, { key: 2, value: '文档' }]
  }
}

// getters
const getters = {
  enumFormat: (state) => (arrary, key) => {
    return format(arrary, key)
  }
}

// actions
const actions = {}

// mutations
const mutations = {}

// 枚举转换
const format = function (array, key) {
  for (let item of array) {
    if (item.key === key) {
      return item.value
    }
  }
  return null
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
